import {
  getHoursBefore,
  getDayBefore,
  getMonthBefore,
  generateRandomValue
} from "./handler";

/**
 * 实时人员数据生成方法
 * @param {Object} key 传入筛选 key
 * @returns {Array<Object>} 返回实时人员数据
 */
export const generatePersonnelData = key => {
  const nameList = [
    "李明",
    "王芳",
    "张伟",
    "王伟",
    "李敏",
    "李静",
    "王静",
    "张静",
    "李磊",
    "王磊",
    "张磊",
    "刘伟",
    "刘芳",
    "刘娜",
    "张敏",
    "刘静",
    "王敏",
    "张明",
    "王燕",
    "李娜",
    "刘敏",
    "张燕",
    "李杰",
    "刘磊",
    "王杰",
    "刘杰",
    "李洋",
    "王洋",
    "张洋",
    "李艳",
    "张杰",
    "王艳",
    "刘洋",
    "刘艳",
    "李丽",
    "王丽",
    "张丽",
    "李军",
    "刘军",
    "王军",
    "张军",
    "刘艳",
    "王丽",
    "张丽",
    "李军",
    "刘军",
    "王军",
    "张军",
    "李丽",
    "王丽",
    "张丽"
  ];
  const typeList = ["进入", "离开"];
  const pointList = ["二号门-侧门", "二号门-正门"];
  const timeList = getHoursBefore();
  const data = [];

  if (key == 1) {
    for (let index = 0; index < 50; index++) {
      data.push({
        name: nameList[index],
        type: typeList[index % 2],
        point: pointList[index % 2],
        time: `11-26 ${timeList[index < timeList.length ? index : 0]}`
      });
    }
  }

  return data;
};

/**
 * 实时车辆数据生成方法
 * @param {Object} key 传入筛选 key
 * @returns {Array<Object>} 返回实时车辆数据
 */
export const generateCarData = key => {
  const licensePlates = [
    "沪A12345",
    "苏B23456",
    "京C34567",
    "京D45678",
    "苏E56789",
    "沪F67890",
    "苏G78901",
    "沪H89012",
    "苏J90123",
    "沪K01234",
    "京L12345",
    "苏M23456",
    "苏N34567",
    "沪P45678",
    "苏Q56789",
    "京R67890",
    "沪S78901",
    "沪T89012",
    "苏U90123",
    "京V01234",
    "苏W12345",
    "沪X23456",
    "沪Y34567",
    "苏Z45678",
    "京A12345",
    "沪B23456",
    "京C34567",
    "苏D45678",
    "苏E56789",
    "沪F67890",
    "苏G78901",
    "沪H89012",
    "苏J90123",
    "沪K01234",
    "京L12345",
    "苏M23456",
    "苏N34567",
    "沪P45678",
    "苏Q56789",
    "京R67890",
    "沪S78901",
    "沪T89012",
    "苏U90123",
    "京V01234",
    "苏W12345",
    "沪X23456",
    "沪Y34567",
    "苏Z45678",
    "京A12345",
    "沪B23456"
  ];
  const typeList = ["进入", "离开"];
  const pointList = ["二号门-侧门", "二号门-正门"];
  const timeList = getHoursBefore();
  const data = [];

  if (key == 1) {
    for (let index = 0; index < 50; index++) {
      data.push({
        name: licensePlates[index],
        type: typeList[index % 2],
        point: pointList[index % 2],
        time: `11-26 ${timeList[index < timeList.length ? index : 0]}`
      });
    }
  }

  return data;
};

/**
 * 流量统计数据生成方法
 * @param {Object} key 传入筛选 key
 * @returns {Array<Object>} 返回工单数据
 */
export const generateFlowStatisticsData = key => {
  const data = [];
  if (key == 0) {
    const timeList = getHoursBefore();
    timeList.forEach(time => {
      data.push({
        name: time,
        enter: generateRandomValue(2),
        exit: generateRandomValue(2)
      });
    });
  }

  if (key == 1) {
    const dayList = getDayBefore();
    dayList.forEach(day => {
      data.push({
        name: day,
        enter: generateRandomValue(3),
        exit: generateRandomValue(3)
      });
    });
  }

  if (key == 2) {
    const monthList = getMonthBefore();
    monthList.forEach(month => {
      data.push({
        name: month,
        enter: generateRandomValue(4),
        exit: generateRandomValue(4)
      });
    });
  }

  return data;
};

/**
 * 电梯数量数据生成方法
 * @returns {Object} 返回电梯数量数据
 */
export const generateElevatorQuantityData = () => {
  return {
    total: 28,
    equipmentList: [
      {
        name: "客梯",
        total: 16,
        abnormal: 1
      },
      {
        name: "货梯",
        total: 8,
        abnormal: 0
      },
      {
        name: "消防梯",
        total: 4,
        abnormal: 1
      }
    ]
  };
};

/**
 * 楼栋相关数据生成方法
 * @returns {Array<Object>} 返回楼栋相关数据
 */
export const generateBuildingData = () => {
  return [
    {
      id: 1,
      name: "A栋",
      children: [
        {
          id: 11,
          name: "A座"
        },
        {
          id: 12,
          name: "B座"
        }
      ]
    },
    {
      id: 2,
      name: "B栋",
      children: [
        {
          id: 21,
          name: "A座"
        },
        {
          id: 22,
          name: "B座"
        },
        {
          id: 23,
          name: "C座"
        }
      ]
    },
    {
      id: 3,
      name: "C栋",
      children: [
        {
          id: 31,
          name: "A座"
        },
        {
          id: 32,
          name: "B座"
        }
      ]
    },
    {
      id: 4,
      name: "D栋",
      children: [
        {
          id: 41,
          name: "A座"
        },
        {
          id: 42,
          name: "B座"
        }
      ]
    },
    {
      id: 5,
      name: "E栋",
      children: [
        {
          id: 51,
          name: "A座"
        },
        {
          id: 52,
          name: "B座"
        }
      ]
    }
  ];
};

/**
 * 楼栋电梯相关数据生成方法
 * @param {Object} isLinear 传入是否线性
 * @param {String|Number} data.mainKey 主 key
 * @param {String|Number} data.subKey 子 key
 * @returns {Array<Object>} 返回楼栋相关数据
 * @description type: 0 ['电梯上行', '电梯下行', '电梯悬停', '电梯故障']
 */
export const generateBuildingElevatorData = (data, isLinear = false) => {
  const elevatorList = [];
  const floorList = [
    "-2F",
    "-1F",
    "1F",
    "2F",
    "3F",
    "4F",
    "5F",
    "6F",
    "7F",
    "8F",
    "9F",
    "10F",
    "11F",
    "12F"
  ];

  if (isLinear) {
    data.forEach(item => {
      let position = item.position;
      let type = 3;
      const maxLength = floorList.length - 1;
      const sept = generateRandomValue(1, 0, 3);
      if (![3].includes(item.type)) {
        if (position == 0) {
          position += sept;
          type = 0;
        } else if (maxLength == position) {
          position -= sept;
          type = 1;
        } else {
          if (!(generateRandomValue(3) % 2)) {
            position = sept + position >= 11 ? 11 : sept + position;
            type = 0;
          } else {
            position = sept - position <= 0 ? 0 : sept - position;
            type = 1;
          }
        }
      }

      elevatorList.push({ ...item, type, position });
    });

    return elevatorList;
  }

  for (let index = 0; index < 6; index++) {
    const pRandomValue = generateRandomValue(2, 0, 11);
    const tRandomValue = generateRandomValue(1, 0, 3);
    const position = pRandomValue;
    const type = tRandomValue;
    const indexFormat = index + 1;
    elevatorList.push({
      id: indexFormat,
      type: type == 2 ? 1 : type,
      name: `#${indexFormat < 10 ? `0${indexFormat}` : indexFormat}`,
      positionArr: floorList,
      position
    });
  }

  return elevatorList;
};

/**
 * 楼栋电梯监控相关数据生成方法
 * @returns {Array<Object>} 返回楼栋电梯监控相关数据
 */
export const generateBuildingElevatorMonitorData = () => {
  return [
    {
      id: 1,
      position: "大厅门口 1号客梯",
      src: "/static/img/park/general/temp/1.webp"
    },
    {
      id: 2,
      position: "2号楼 3号客梯",
      src: "/static/img/park/general/temp/2.webp"
    },
    {
      id: 3,
      position: "3号楼 1号客梯 ",
      src: "/static/img/park/general/temp/3.webp"
    },
    {
      id: 4,
      position: "地下停车场左侧 1号客梯",
      src: "/static/img/park/general/temp/4.webp"
    }
  ];
};
